package com.morgan.maxfunding;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class NewContactUsActivity extends Activity {
	
	LinearLayout llytHeader;

	public Button btnSubmit;
	
	public EditText edtFullName;
	public EditText edtPhone;
	public EditText edtEmail;
	public EditText edtMessage;
	
	public ImageView imgPhone;
	public ImageView imgEmail;
	public ImageView imgFax;
	
	public LinearLayout llytPhone;
	public LinearLayout llytEmail;
	public LinearLayout llytFax;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_new_contact_us);
		
		initWidget();
		initValue();
		initEvent();
	}
	
	private void initWidget() {
		
		llytHeader			= (LinearLayout) findViewById(R.id.header_linearLayout);

		edtFullName 	= (EditText) findViewById(R.id.index_full_name_editText);
		edtPhone		= (EditText) findViewById(R.id.index_phone_editText);
		edtEmail		= (EditText) findViewById(R.id.index_email_editText);
		edtMessage		= (EditText) findViewById(R.id.index_message_editText);
		
		imgPhone		= (ImageView) findViewById(R.id.phone_imageView);
		imgEmail		= (ImageView) findViewById(R.id.email_imageView);
		imgFax			= (ImageView) findViewById(R.id.fax_imageView);
		
		llytPhone		= (LinearLayout) findViewById(R.id.phone_linearLayout);
		llytEmail		= (LinearLayout) findViewById(R.id.email_lineayLayout);
		llytFax			= (LinearLayout) findViewById(R.id.fax_linearLayout);
		
		btnSubmit		= (Button)	findViewById(R.id.index_submit_button);
	}
	
	private void initValue() {
		
	}
	
	private void initEvent() {
		
		llytHeader.setOnClickListener(new Button.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maxfunding.com.au"));
				startActivity(browserIntent);
			}
        });
		
		btnSubmit.setOnClickListener(new Button.OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				
 				try {
 					String strFullName 	= edtFullName.getText().toString();
 					String strPhone		= edtPhone.getText().toString();
 					String strEmail		= edtEmail.getText().toString();
 					String strMessage	= edtMessage.getText().toString();
 					
 					if (strFullName.equals("")) {
 						showGeneralAlert("Input Error", "Please input Full Name!");
 						return;
 					}
 					if (strEmail.equals("")) {
 						showGeneralAlert("Input Error", "Please input Email address!");
 						return;
 					}
 					if (strMessage.equals("")) {
 						showGeneralAlert("Input Error", "Please input Message!");
 						return;
 					}
 					new MyAsyncTask(NewContactUsActivity.this, MyAsyncTask.ACTION_CONTACT_US).execute(MyAsyncTask.ACTION_CONTACT_US, strFullName, strPhone, strEmail, strMessage);
 				} catch (Exception e) {
 					
 				}
 			}
   	 	});
		/*
		imgPhone.setOnClickListener(new Button.OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				//showGeneralAlert("test", "phone_call");
 				Intent dial = new Intent(Intent.ACTION_CALL);
 		        dial.setData(Uri.parse("tel:" + "1300411411"));
 		        startActivity(dial);
 			}
   	 	});
		
		imgEmail.setOnClickListener(new Button.OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				//showGeneralAlert("test", "email_call");
 				Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
				email.putExtra(Intent.EXTRA_EMAIL, new String[] {"Business@MaxFunding.com.au"});
				email.putExtra(Intent.EXTRA_SUBJECT, "Mobile App technical error report");
				email.setType("text/plain");
				startActivity(Intent.createChooser(email, "E-mail"));
 			}
   	 	});
		
		imgFax.setOnClickListener(new Button.OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				
 			}
   	 	});
		*/
		llytPhone.setOnClickListener(new Button.OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				//showGeneralAlert("test", "phone_call");
 				Intent dial = new Intent(Intent.ACTION_CALL);
 		        dial.setData(Uri.parse("tel:" + "1300411411"));
 		        startActivity(dial);
 			}
   	 	});
		
		llytEmail.setOnClickListener(new Button.OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				//showGeneralAlert("test", "email_call");
 				Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
				email.putExtra(Intent.EXTRA_EMAIL, new String[] {"Business@MaxFunding.com.au"});
				email.putExtra(Intent.EXTRA_SUBJECT, "Mobile App technical error report");
				email.setType("text/plain");
				startActivity(Intent.createChooser(email, "E-mail"));
 			}
   	 	});
		
		llytFax.setOnClickListener(new Button.OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				
 			}
   	 	});
	}
	
    public void showGeneralAlert(String title, String message) {
     	new AlertDialog.Builder(NewContactUsActivity.this)
     	
         .setTitle(title)
         .setMessage(message)
         .setPositiveButton("OK", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
                 // continue with delete
             }
          })
          .show();
    }
    
    public void completeSubmit() {
    	new AlertDialog.Builder(NewContactUsActivity.this)
     	
        .setTitle("")
        .setMessage("Your form is submitted successfully.")
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // continue with delete
            	NewContactUsActivity.this.finish();
            }
         })
         .show();
    }
}
